package com.wechat.admin.model.vo;

import com.wechat.admin.model.dto.CurrentUserInfoDto;
import com.wechat.admin.model.dto.UserInfoDto;
import lombok.Data;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

/**
 * @Author:sjb
 * @CreateTime:2024-12-14
 * @Description: 登录用户信息
 * @Version：1.0
 */
@Setter
@Data
public class UserLoginInfoVo implements UserDetails {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String username;

    private String userRole;

    private Integer userGroup;

    public static UserLoginInfoVo dtoToVo (CurrentUserInfoDto userInfoDto){
        if (userInfoDto==null){
            return null;
        }
        UserLoginInfoVo loginUserVo = new UserLoginInfoVo();
        loginUserVo.setId(userInfoDto.getId());
        loginUserVo.setUserGroup(userInfoDto.getUserGroup());
        loginUserVo.setUserRole(userInfoDto.getUserRole());
        loginUserVo.setUsername(userInfoDto.getUserAccount());
        return loginUserVo;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return "";
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
